package Work3;
import java.util.Random;
import java.util.Scanner;
import java.util.ArrayList;

public class Member {
	public wallet wal = new wallet();
	private String name;
	private int id;
	public void setname(String name) {
		this.name=name;
	}
	public void setid(int id) {
		this.id=id;
	}
	public String getname() {
		return this.name;
	}
	public int getid() {
		return this.id;
	}
	public void showmoney() {
		System.out.println("余额:"+wal.getMoney());
	}
	public hongbaoinfo Send() {
		Random rd=new Random();
		hongbaoinfo hb=new hongbaoinfo();
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入红包金额和人数");
		System.out.println("金额:");
		int money = sc.nextInt();
		System.out.println("人数:");
		int people = sc.nextInt();
		while(!wal.Pay(money)) {
		System.out.println("余额不足,请重新输入红包金额和人数");
		System.out.println("金额:");
		money = sc.nextInt();
		System.out.println("人数:");
		people = sc.nextInt();
		}
		hb.setmoney(money);
		hb.setpeople(people);
		hb.setname(this.name);
		ArrayList<Integer> hongbao = new ArrayList<Integer>();
		int temp;
		for(int i=0;i<people;i++) {
			if(i==people-1) {
				temp=money;
			}else {
				temp=rd.nextInt(1,money/(people-i)*2);
			}
			hongbao.add(temp);
			money-=temp;
		}
		hb.sethongbao(hongbao);
		return hb;
	}
	public void GetHongbao(Member mb,hongbaoinfo hb) {
		if(hb.getpeople.contains(mb.getname())) {
			System.out.println("你抢过了");
			return;
		}
		if(hb.getpeople.size()==hb.getpeople()) {
			System.out.println("红包抢完了");
			return;
		}
		Random rd=new Random();
		int num = rd.nextInt(hb.gethongbao().size());
		wal.Get(hb.gethongbao().get(num));
		hb.getpeople.add(mb.getname());
		hb.getmoney.add(hb.gethongbao().get(num));
		System.out.println("抢到了"+hb.gethongbao().get(num)+"元");
		showmoney();
		hb.gethongbao().remove(num);
	}
}
